#include "NBE.h"

#include "DllLoader.h"
#include <windows.h>
namespace NBE
{
	DllLoader::DllLoader()
		:m_dll(nullptr)
	{}

	DllLoader::~DllLoader()
	{
		FreeLibrary(m_dll);
	}

	bool DllLoader::load(wchar_t* dllName)
	{
		m_dll = LoadLibrary(dllName);//load dll
		return m_dll != nullptr;
	}

	void* DllLoader::getProcAddress(char* funcName)
	{
		typedef void* (__cdecl* FuncPointer)(HINSTANCE h);
		FuncPointer ptr_someFunc;
		ptr_someFunc = (FuncPointer) GetProcAddress(m_dll,funcName);
		if(ptr_someFunc == nullptr)
		{
			throw NBEException(CantGetFuncInDll);
		}

		return ptr_someFunc;
	}

}